package com.example.sys.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.config.ResponseBean;
import com.example.config.UnicomResponseEnums;
import com.example.sys.entity.OperLog;
import com.example.sys.service.OperLogService;
import com.example.sys.vo.OperLogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 操作日志记录 前端控制器
 * </p>
 *
 * @author anan
 * @since 2019-06-20
 */
@RestController
@RequestMapping("/sys/oper-log")
public class OperLogController {

    @Autowired
    private OperLogService operLogService;

    @GetMapping("/getOperLogList")
    public ResponseBean<UnicomResponseEnums> getOperLogList(OperLogVo operLogVo){
        System.out.println(operLogVo);
        Map<String, Object> stringObjectMap = BeanUtil.beanToMap(operLogVo, false, true);
        if (stringObjectMap.isEmpty()){
            List<OperLog> operLogs=operLogService.list();
            return new ResponseBean(true, operLogs, UnicomResponseEnums.SUCCESS_OPTION);
        }
        return new ResponseBean(true, operLogService.selectPage(operLogVo), UnicomResponseEnums.SUCCESS_OPTION);
    }

    @DeleteMapping("/deleteOperLogs")
    public ResponseBean<UnicomResponseEnums> deleteOperLogs(){
        QueryWrapper<OperLog> wrapper = new QueryWrapper<>();
        wrapper.eq("1", 1);
        if (operLogService.remove(wrapper)){
            return new ResponseBean(true, UnicomResponseEnums.SUCCESS_OPTION);
        }
        return new ResponseBean(true, UnicomResponseEnums.OPERATION_FAILED);
    }


}
